home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 423_01 / recio200 / rbget.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-15  |  2.2 KB  |  64 lines

  1. /*****************************************************************************
  2.    MODULE: rbget.c
  3.   PURPOSE: recio character delimited integral number input functions
  4. COPYRIGHT: (C) 1994 William Pierpoint
  5.  COMPILER: Borland C Version 3.1
  6.        OS: MSDOS Version 6.2
  7.   VERSION: 2.00
  8.   RELEASE: April 15, 1994
  9. *****************************************************************************/
  10.  
  11. #include <ctype.h>
  12. #include <errno.h>
  13. #include <limits.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. #include "_rbget.h"
  19.  
  20. /****************************************************************************/
  21. unsigned long                /* return unsigned long                        */
  22.     str2ul(                  /* convert string to unsigned long             */
  23.         const char  *nptr,   /* pointer to string to convert                */
  24.               char **endptr, /* pointer to conversion leftover string       */
  25.               int    base)   /* base (radix) of number                      */
  26. /****************************************************************************/
  27. /* note: unlike strtoul, str2ul tests for a negative number */
  28. {
  29.     unsigned long ul=0UL;    /* result to return */
  30.     const char   *np=nptr;   /* pointer to string */
  31.  
  32.     errno = 0;
  33.  
  34.     /* skip over white space */
  35.     while (isspace(*np)) np++;
  36.     
  37.     /* if first non-white space is a minus sign */
  38.     if (*np == '-') {
  39.         
  40.         /* position endptr at the minus sign */
  41.         if (endptr) *endptr = (char *) np;
  42.  
  43.     } else {
  44.  
  45.         ul = strtoul(nptr, endptr, base);
  46.  
  47.     } 
  48.     return (ul);
  49. }
  50.  
  51. /****************************************************************************/
  52. /* rbget_fn() - define rbget functions                                      */
  53. /****************************************************************************/
  54. #define uint   unsigned int
  55. #define ulong  unsigned long
  56. #ifdef __BORLANDC__
  57. #pragma warn -ccc
  58. #endif
  59.  
  60. rbget_fn(   int,  rbgeti,  0,  long, strtol,  INT_MIN,   INT_MAX)
  61. rbget_fn(  uint, rbgetui,  0, ulong, str2ul,        0,  UINT_MAX)
  62. rbget_fn(  long,  rbgetl, 0L,  long, strtol, LONG_MIN,  LONG_MAX)
  63. rbget_fn( ulong, rbgetul, 0L, ulong, str2ul,        0, ULONG_MAX)
  64.